#ifndef SrcBrowser_First
#define SrcBrowser_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Document.h"
#include "CodeTextView.h"
#include "Mark.h"

class PeSrcBrowserTextView;
class PeClassListView;
class PeMethodBrowser;
class PeImplementors;
class VObjectText;
class OrdCollection;
class Data;
class PeMethodReference;
class PrettyPrinter;
class TextField;

//---- SourceBrowser -----------------------------------------------------------

class PeSourceBrowser: public Document {
public:
	MetaDef(PeSourceBrowser);
	PeSourceBrowser(Manager *m);
	~PeSourceBrowser();

	VObject *DoMakeContent();
	bool LoadData(Data *data, bool unique);
	void SetWindowTitle(const char *name);

	bool DoReadData(Data *data);
	bool DoWrite(OStream &s, Data*);
	bool CanImport(Data*);
	Command *DoImport(Data*);
	void CollectParts(Collection *col);

	void SetClass(Class*, bool decl, bool reveal= TRUE);
	void DoSetClass(Class*, bool decl, bool unique, bool reveal);
	void RevealMethod(PeMethodReference *mr);
	void RevealAndSelectLine(int l);
	void SelectSourceLine(bool redraw);
	bool FileOfClass(Class *cl, char *fname, bool decl);
	void SetMode(bool decl);
	void Spawn();
	Class *GetClass()
		{ return ccl; }
	bool GetMode()
		{ return definition; }

	//---- menus
	MenuBar *DoMakeMenuBar();
	Command *DoMenuCommand(int cmd);
	void DoSetupMenu(Menu *menu);

	void Control(int id, int part, void *val);
	void InputKbd(Token &t);

	//--- commands
	void Log(Class *cl);
	void EditSelectedClass();
	void ShowImplementors();
	void InspectSomeInstance();

	static void ShowClass(Manager *m, Class *cp, bool decl, int at= -1);
	static void Spawn(Manager *m, Class *cp, bool decl, int at= -1);

private:
	char *FirstWordOfSelection();

private:
	static PeSourceBrowser *browser;
	static int srcCount;

	VObject *classScroller;
	VObject *methodScroller;
	PeSrcBrowserTextView *textview;
	PeClassListView *listview;
	PeMethodBrowser *methods;
	PeImplementors *implementors;
	TextField *implTitle;
	VObjectText *text;
	Class *ccl;

	bool isCCode, definition, base;
	OrdCollection *log;

};

//---- SrcBrowserTextView ------------------------------------------------------

class PeSrcBrowserTextView: public CodeTextView {
public:
	MetaDef(PeSrcBrowserTextView);
	PeSrcBrowserTextView(EvtHandler *eh, Rectangle r, VObjectText *t);

	PrettyPrinter *MakePrettyPrinter(Text *t, CharStyle *cs, CharStyle *fs,
						CharStyle *cds, CharStyle *ps);

	void ShowMethod(PeMethodReference *mr);
};

//---- PeSrcBrowserPPrinter ----------------------------------------------------

class PeSrcBrowserPPrinter : public PrettyPrinter {
	PeSrcBrowserTextView *tvp;
public:
	PeSrcBrowserPPrinter(PeSrcBrowserTextView *tvp, Text *t,
		CharStyle *cs, CharStyle *fs, CharStyle *cds, CharStyle *ps);
	void Function(int line, int start, int end, const char *name,
														const char *classname);
};

//---- PeMethodMark ------------------------------------------------------------

class PeMethodMark: public Mark {
public:
	MetaDef(PeMethodMark);
	PeMethodMark(const char *classname, const char *method, int p= 0,
									int l= 0);
	~PeMethodMark();
public:
	char *className, *method;
};

#endif

